package com.endava.spring.dao_impl;

import java.util.List;

import com.endava.spring.beans.Person;
import com.endava.spring.dao_interface.DataSourceDao;
import com.endava.spring.dao_interface.PersonDao;

/**
 * Implements the methods of interface <code>PersonDao</code>.
 * 
 * @author acojocar
 * @since 30.07.2013
 * @version 1.0
 * 
 */
public class PersonJDBCTemplate extends DataSourceDao implements PersonDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Person> read() {
		List<Person> persons = jdbcTemplate.query(SELECT_QUERY,
				new PersonMapper());
		return persons;
	}

	@Override
	public void create(Integer personID, String firstName, String lastName,
			String address) {
		jdbcTemplate.update(INSERT_QUERY, new Object[] { personID, firstName,
				lastName, address });
	}

	@Override
	public void deleteAccount(Integer personID) {
		jdbcTemplate.update(DELETE_QUERY, new Integer[] { personID });
	}

	@Override
	public void update(Integer personID, String address) {
		jdbcTemplate.update(UPDATE_QUERY, new Object[] { address,
				new Integer(personID) });
	}

}
